home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Complementary Applications 2004 May / SGI IRIX 6.5 Complementary Applications 2004 May.iso / dist / OpenOffice.idb / usr / OpenOffice / help / en / sbasic.jar / text / sbasic / common / 03090201.xml < prev    next >
Encoding:
Extensible Markup Language  |  2002-01-24  |  6.8 KB  |  78 lines

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <html><head><title>Do...Loop Statement [Runtime]</title><meta name="filename" content="text/sbasic/common/03090201"/><meta name="language" content="en-US"/><help:css-file-link xmlns:help="http://openoffice.org/2000/help"/><!--The CSS style header method for setting styles--><style type="text/css">
  3.  
  4.         p.P1{
  5.                 }
  6.         p.P2{
  7.                 }
  8.         span.T1{
  9.                 font-weight:bold;}
  10.         </style></head><body>
  11.   
  12.   
  13.   <help:to-be-embedded Eid="doloop" xmlns:help="http://openoffice.org/2000/help"><a name="doloop"/>
  14.   <p class="Head1"><help:link Id="66463">Do...Loop Statement [Runtime]</help:link></p>
  15.   <p class="Paragraph">Repeats the statements between the Do and the Loop statement while the condition is True or until the condition becomes True.</p>
  16.   </help:to-be-embedded>
  17.   <p class="P2">Syntax</p>
  18.   <p class="Paragraph"><help:key-word value="Do" tag="kw66463_1" xmlns:help="http://openoffice.org/2000/help"/>Do [{<help:key-word value="While" tag="kw66463_4" xmlns:help="http://openoffice.org/2000/help"/>While | <help:key-word value="Until" tag="kw66463_3" xmlns:help="http://openoffice.org/2000/help"/>Until} condition = True]</p>
  19.   <p class="Paragraph">statement block</p>
  20.   <p class="P2">[Exit Do]</p>
  21.   <p class="Paragraph">statement block</p>
  22.   <p class="Paragraph"><help:key-word value="Loop" tag="kw66463_2" xmlns:help="http://openoffice.org/2000/help"/>Loop</p>
  23.   <p class="Paragraph">or</p>
  24.   <p class="Paragraph">Do</p>
  25.   <p class="Paragraph">statement block</p>
  26.   <p class="Paragraph">[Exit Do]</p>
  27.   <p class="Paragraph">statement block</p>
  28.   <p class="Paragraph">Loop [{While | Until} condition = True]</p>
  29.   <p class="P2">Param./Element</p>
  30.   <p class="Paragraph">Condition: A comparison, numeric or string expression that evaluates either True or False.</p>
  31.   <p class="Paragraph">Statement block: Statements to be repeated while or until the condition is True.</p>
  32.   <p class="Paragraph"><span class="T1">The Do...Loop</span> statement is used to execute a loop as long as (or until) a certain condition is True. The condition for exiting the loop must be entered following either the <span class="T1">Do</span> or the <span class="T1">Loop</span> statement. The following examples are valid combinations:</p>
  33.   <p class="P2">Syntax</p>
  34.   <p class="Paragraph">Do While condition = True</p>
  35.   <p class="Paragraph">...statement block</p>
  36.   <p class="P2">Loop</p>
  37.   <p class="Paragraph">The program tests the condition. If the condition is False, the program continues directly after the <span class="T1">Loop</span> <text:s text:c="" xmlns:text="http://openoffice.org/2000/text"/>statement. If the condition is True, the <span class="T1">loop</span> is activated, and the program jumps back to the <span class="T1">Do</span> <text:s text:c="" xmlns:text="http://openoffice.org/2000/text"/>statement. If the condition is still True, the loop will be repeated, otherwise the program execution continues with the statement following the <span class="T1">Loop</span> statement.</p>
  38.   <p class="Paragraph">To summarize: The loop will be repeated as long as the condition is true.</p>
  39.   <p class="Paragraph">Do Until condition = True</p>
  40.   <p class="Paragraph">...statement block</p>
  41.   <p class="Paragraph">Loop</p>
  42.   <p class="Paragraph">The program tests the condition. If the condition is True, the program continues directly after the <span class="T1">Loop</span> <text:s text:c="" xmlns:text="http://openoffice.org/2000/text"/>statement. If the condition is not True, the <span class="T1">loop</span> is activated, and the program jumps back to the <span class="T1">Do</span> statement. If the condition is still not True, the loop will be repeated, otherwise the program execution continues with the statement following the <span class="T1">Loop</span> statement.</p>
  43.   <p class="Paragraph">To summarize: The loop will only be repeated, if the condition is False at first, and then until the condition becomes true.</p>
  44.   <p class="Paragraph">Do</p>
  45.   <p class="Paragraph">...statement block</p>
  46.   <p class="Paragraph">Loop While condition = True</p>
  47.   <p class="Paragraph">The program initiates the loop immediately. At the <span class="T1">Loop</span> statement, the condition is tested. If the condition is True, the program repeats the loop starting from the <span class="T1">Do</span> statement. Only when the condition following <span class="T1">Loop</span> becomes False,the program will end the loop.</p>
  48.   <p class="Paragraph">To summarize: The statements within the loop <text:s text:c="" xmlns:text="http://openoffice.org/2000/text"/>will be executed once in each case, and as long as the condition is true.</p>
  49.   <p class="Paragraph">Do</p>
  50.   <p class="Paragraph">...statement block</p>
  51.   <p class="Paragraph">Loop Until condition = True</p>
  52.   <p class="Paragraph">The program initiates the loop immediately. At the <span class="T1">Loop</span> statement, the condition is tested. If the condition is not True, the program repeats the loop starting from the <span class="T1">Do</span> statement. Only when the condition following <span class="T1">Loop</span> <text:s text:c="" xmlns:text="http://openoffice.org/2000/text"/>becomes True, the program will end the loop.</p>
  53.   <p class="Paragraph">To summarize: The statements within the loop will be executed once in each case, and until the condition becomes true.</p>
  54.   <p class="Paragraph">The main difference between the above mentioned statements is that in the first two cases, the loop is initiated dependent on the condition. In the last two examples, the statements between <span class="T1">Do</span> und <span class="T1">Loop</span> are executed once at least.</p>
  55.   <p class="Paragraph">The <span class="T1">Exit Do</span> statement ends the loop unconditionally. This statement is placed anywhere within a <span class="T1">Do</span>...<span class="T1">Loop</span> statement. You can define an exit condition using the <span class="T1">If...Then</span> structure as follows:</p>
  56.   <p class="Paragraph">Do...</p>
  57.   <p class="Paragraph">statements</p>
  58.   <p class="Paragraph">If condition = True Then Exit Do</p>
  59.   <p class="Paragraph">statements</p>
  60.   <p class="Paragraph">Loop...</p>
  61.   <p class="P2">Example</p>
  62.   <p class="Paragraph"/>
  63.   <p class="Paragraph">Sub ExampleDoLoop</p>
  64.   <p class="Paragraph">Dim sFile As String</p>
  65.   <p class="PropText">Dim sPath As String</p>
  66.   <p class="PropText">sPath = "c:\"</p>
  67.   <p class="PropText">sFile = Dir$( sPath ,22)</p>
  68.   <p class="PropText">If sFile <> "" Then</p>
  69.   <p class="PropText">Do</p>
  70.   <p class="PropText">MsgBox sFile</p>
  71.   <p class="PropText">sFile = Dir$</p>
  72.   <p class="PropText">Loop Until sFile = ""</p>
  73.   <p class="PropText">End If</p>
  74.   <p class="PropText">End Sub</p>
  75.   <p class="PropText"/>
  76.   <p class="PropText"/>
  77.   <p class="PropText"/>
  78.  </body></html>